// utils/http.js
let baseURL = '';
const key = '3c6a40f9b2aa4f1c978b272e2914d9e2'
const request = (options) => {
	baseURL = options.url + '&key=' + key
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL,
			method: options.method || 'GET',
			data: options.data || {},
			success: (res) => {
				if (res.statusCode === 401) { // Token过期处理
					uni.navigateTo({
						url: '/pages/login/login'
					});
					reject('Token过期，请重新登录');
				} else {
					resolve(res.data);
				}
			},
			fail: (err) => {
				uni.showToast({
					title: '网络请求失败',
					icon: 'none'
				});
				reject(err);
			}
		});
	});
};

export default request;